﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Entity
{
    [Table("wms_knzy_inventory_list")]
    public class InventoryListEntity
    {
        // 状态常量定义
        public const int STATUS_DRAFT = 0;           // 草稿
        public const int STATUS_PENDING_REVIEW = 1;  // 待审核
        public const int STATUS_APPROVED_WITH_PROFIT_LOSS = 2; // 已审核（有盈亏）
        public const int STATUS_APPROVED_WITHOUT_PROFIT_LOSS = 3; // 已审核（无盈亏）
        public const int STATUS_CANCELLED = 4;       // 作废

        [Key]
        public int inventory_list_id { get; set; }

        [Required, MaxLength(50)]
        public string inventory_order_no { get; set; }


        public string inventory_types { get; set; }
        public int review_status { get; set; } = STATUS_DRAFT;

        // 新增 outbound_status 属性
        public string outbound_status { get; set; } = "0"; // 默认值：0-未出库
        public int storage_status { get; set; }

        [MaxLength(50)]
        public string reviewer { get; set; } = "";
        public DateTime? review_time { get; set; }

        public DateTime? inventory_start_time { get; set; }
        public DateTime? stkt_end_time { get; set; } // 盘点结束时间（原inventory_end_time）

        [Required, MaxLength(100)]
        public string warehouse_name { get; set; }

        [MaxLength(50)]
        public string handler_id { get; set; }
        public string handler_name { get; set; } // 新增：经办人名称（用于前端显示）
        public int? organizations_id { get; set; }
        public string department_name { get; set; } // 新增：部门名称

        [MaxLength(200)]
        public string note { get; set; }

        [MaxLength(50)]
        public string create_by { get; set; }
        public DateTime? create_time { get; set; }

        [MaxLength(50)]
        public string update_by { get; set; }
        public DateTime? update_time { get; set; }

        // 核心修改：适配数据库char(1)类型，用string存储'0'（未删除）或'1'（已删除）
        [MaxLength(1)]  // 限制长度为1，匹配char(1)
        public string is_delete { get; set; } = "0";  // 默认未删除
      // 补充缺失的属性
        public int? total_profit_num { get; set; } // 盘盈数量
        public int? total_loss_num { get; set; }   // 盘亏数量
        public decimal? total_profit_amount { get; set; } // 盘盈金额
        public decimal? total_loss_amount { get; set; }   // 盘亏金额
        // 新增：用于展示明细汇总的字段
        [NotMapped] // 非数据库字段，仅用于前端展示
        public string product_names { get; set; } // 拼接的货品名称，如"商品1，商品2"

        [NotMapped] // 非数据库字段，仅用于前端展示
        public decimal total_quantity { get; set; } // 盘点总数量
    }
    public class InventoryDetailWithProductName
    {
        // 明细表字段（与InventoryDetailsEntity一致）
        public int inventory_detail_id { get; set; }
        public int inventory_list_id { get; set; }
        public string product_code { get; set; }
        public int book_inventory { get; set; }
        public decimal book_amount { get; set; }
        public string inventory_location { get; set; }
        public int stkt_num { get; set; }
        public int pl_num { get; set; }
        public string inventory_status { get; set; }
        public decimal reference_unit_price { get; set; }
        public decimal profit_and_loss_amount { get; set; }
        public string note { get; set; }
        public string create_by { get; set; }
        public DateTime create_time { get; set; }
        public string update_by { get; set; }
        public DateTime? update_time { get; set; }
        public string is_delete { get; set; }

        // 从产品表关联的字段
        public string product_name { get; set; }  // 核心：产品名称
    }
}